import axios from 'axios';

const API_BASE_URL = ''; // 替换为你的API基础URL

// 获取问卷列表
export const getQuestionnaireList = async (params: {
  current: number;
  pageSize: number;
  tag?: string;
  dateRange?: string[];
  keyword?: string;
}) => {
  try {
    const response = await axios.post(`${API_BASE_URL}/questionnaire/getList`, {
        page: params.current,
        size: params.pageSize,
        condition:{
        }
    });
    return response.data;
  } catch (error) {
    console.error('获取问卷列表失败', error);
    throw error;
  }
};

// 保存问卷（新增或编辑）
export const saveQuestionnaire = async (questionnaire: {
  id?: string;
  title: string;
  type: string;
  projectType: string;
  status: string;
}) => {
  try {
    const url = questionnaire.id
      ? `${API_BASE_URL}/questionnaire/saveQuestionnaire`
      : `${API_BASE_URL}/questionnaire/saveQuestionnaire`;
    const method = questionnaire.id ? 'post' : 'post';

    const response = await axios({
      method,
      url,
      data: questionnaire,
    });
    return response.data;
  } catch (error) {
    console.error('保存问卷失败', error);
    throw error;
  }
};

// 删除问卷
export const deleteQuestionnaire = async (id: string) => {
  try {
    const response = await axios.delete(`${API_BASE_URL}/questionnaires/${id}`);
    return response.data;
  } catch (error) {
    console.error('删除问卷失败', error);
    throw error;
  }
};


// 获取问卷结果列表
export const getQuestionnaireResultList = async (params: {
  current: number;
  pageSize: number;
  productType?: string;
  chargeType?: string;
  serviceNo?: string;
}) => {
  try {
    const response = await axios.post(`${API_BASE_URL}/questionnaireResult/getList`, {
      page: params.current,
      size: params.pageSize,
      condition: {
        productType: params.productType,
        chargeType: params.chargeType,
        serviceNo: params.serviceNo,
      },
    });
    return response.data;
  } catch (error) {
    console.error('获取问卷结果列表失败', error);
    throw error;
  }
};

// 获取问卷结果详情
export const getQuestionnaireResultDetail = async (id: string) => {
  try {
    const response = await axios.get(`${API_BASE_URL}/questionnaireResult/getDetail`, {
      params: {
        id,
      },
    });
    return response.data;
  } catch (error) {
    console.error('获取问卷结果详情失败', error);
    throw error;
  }
}